package com.icetec.iceintel.framework.dragGridView;

import android.widget.BaseAdapter;

import com.icetec.iceintel.model.Device;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @blog http://blog.csdn.net/xiaanming 
 * 
 * @author xiaanming
 *
 */
public abstract class DragAdapter extends BaseAdapter implements DragGridBaseAdapter{
	protected int mHidePosition = -1;


	@Override
	public void reorderItems(int oldPosition, int newPosition) {
		Object temp = getList().get(oldPosition);
		if(oldPosition < newPosition){
			for(int i=oldPosition; i<newPosition; i++){
				Collections.swap(getList(), i, i + 1);
			}
		}else if(oldPosition > newPosition){
			for(int i=oldPosition; i>newPosition; i--){
				Collections.swap(getList(), i, i - 1);
			}
		}

		getList().set(newPosition, temp);
	}

	@Override
	public void setHideItem(int hidePosition) {
		this.mHidePosition = hidePosition; 
		notifyDataSetChanged();
	}

	@Override
	public void removeItem(int removePosition) {
		getList().remove(removePosition);
		notifyDataSetChanged();
	}

	public abstract List<Object> getList();

}
